package com.itmuch.cloud.movieservice.controller;

import java.io.File;
import java.io.FileOutputStream;

import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class FileUploadController {

	@RequestMapping(name="/fileUpload", method=RequestMethod.POST)
	@ResponseBody
	public String fileUpload(@RequestParam(value="file",required=false) MultipartFile multipartFile) {
		try {
			File file = new File(multipartFile.getOriginalFilename());
			File outFile = new File("/Users/jianganming/"+file.getName());
			FileOutputStream out = new FileOutputStream(outFile);
			FileCopyUtils.copy(multipartFile.getInputStream(), out);
			return outFile.getAbsolutePath();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
}
